package br.unirio.analise_dna.entity;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.commons.mail.EmailException;

public class Email {
	
	private String last_name;
	private String email;
	private String subject;
	private String message;
	private String first_name;
	
	

	public String getLast_name() {
		return last_name;
	}



	public void setLast_name(String last_name) {
		this.last_name = last_name;
	}



	public String getEmail() {
		return email;
	}



	public void setEmail(String email) {
		this.email = email;
	}



	public String getSubject() {
		return subject;
	}



	public void setSubject(String subject) {
		this.subject = subject;
	}



	public String getMessage() {
		return message;
	}



	public void setMessage(String message) {
		this.message = message;
	}



	public String getFirst_name() {
		return first_name;
	}



	public void setFirst_name(String first_name) {
		this.first_name = first_name;
	}



	public void enviarEmail () throws EmailException{
		
				
		try	{
			Properties props=new Properties();
			props.put("mail.transport.protocol", "smtp");
			props.put("mail.smtp.host","smtp.gmail.com");
			props.put("mail.smtp.port", "25");
			props.put("mail.smtp.starttls.enable", "true"); 
			props.put("mail.smtp.auth", "true");
			javax.mail.Authenticator authenticator = new javax.mail.Authenticator() {
				protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
					return new javax.mail.PasswordAuthentication("paulinhac.araujo@gmail.com", "dermazine");
				}
			};
			Session sess = Session.getDefaultInstance(props,authenticator);
			sess.setDebug (true);
			Transport transport = sess.getTransport ("smtp");
			Message msg = new MimeMessage(sess);
			msg.setFrom(new InternetAddress(email));

			msg.addRecipient(Message.RecipientType.TO, new InternetAddress("paulinhac.araujo@gmail.com"));
			msg.setSubject(subject);
			msg.setText(message);

			transport.connect();
			Transport.send(msg);
		}
		catch(Exception e){
			System.out.println("err"+e);
		}
	}
		
}